package com.zhku.shoppingspringboot.controller;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zhku.shoppingspringboot.common.R;
import com.zhku.shoppingspringboot.pojo.dto.CommentDTO;
import com.zhku.shoppingspringboot.pojo.dto.SubmitOrderDTO;
import com.zhku.shoppingspringboot.pojo.entity.Orders;
import com.zhku.shoppingspringboot.pojo.vo.order.CreateOrdersVO;
import com.zhku.shoppingspringboot.pojo.vo.SubmitOrderVO;
import com.zhku.shoppingspringboot.pojo.vo.order.OrderDetailVO;
import com.zhku.shoppingspringboot.pojo.vo.order.OrdersStaticVO;
import com.zhku.shoppingspringboot.service.IOrdersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

import static com.zhku.shoppingspringboot.common.ResultCode.ERROR;

/**
 * @author hwy
 * @date 2025-01-02 00:27
 */
@RestController
@RequestMapping("/member/order")
@Slf4j
@Api(tags = "订单管理")
public class OrderController {
    @Autowired
    private IOrdersService iOrdersService;

    @ApiOperation("生成订单")
    @GetMapping("/pre")
    public R<CreateOrdersVO> createOrder(){
        CreateOrdersVO createOrdersVO = iOrdersService.createOrder();
        if(ObjectUtil.isEmpty(createOrdersVO)){
            return R.error(ERROR,"操作失败");
        }
        return R.success(createOrdersVO);
    }

    @ApiOperation("提交订单")
    @PostMapping()
    public R<SubmitOrderVO> submitOrder(
            @RequestBody
            SubmitOrderDTO submitOrderDTO
    ){
        SubmitOrderVO submitOrderVO = iOrdersService.submitOrder(submitOrderDTO);
        return R.success(submitOrderVO);
    }

    @ApiOperation("获取用户本人所有订单")
    @GetMapping("/allOrder")
    public R<List<OrderDetailVO>> getOrder(){
        return R.success( iOrdersService.getOrder());

    }

    @ApiOperation("发布评论")
    @PutMapping("/comment")
    public R<String> Comment(
            @RequestBody
            CommentDTO comment
    ){
        return iOrdersService.Comment(comment.getId(), comment.getComment());
    }


    @ApiOperation("删除订单(管理员)")
    @DeleteMapping()
    public R<String> deleteOrder(
            @RequestParam
            @Parameter(description = "订单id")
            List<Long> ids
    ){
        return iOrdersService.deleteOrder(ids);
    }

    @ApiOperation("确认收货")
    @PutMapping("/correct/{id}")
    private R<String> correctOedre(
            @PathVariable("id")
            Long id
    ){
        return iOrdersService.correctOrder(id);
    }

    @ApiOperation("查看所有订单(管理员)")
    @GetMapping()
    public R<List<OrderDetailVO>> getAllOrder(){
        return R.success(iOrdersService.getAllOrder());
    }
    @ApiOperation("发货(管理员)")
    @PutMapping("/send/{id}")
    public R<String> sendOrder(
            @PathVariable("id")
            Long id
    ){
        return iOrdersService.sendOrder(id);
    }


}
